package com.myapp.struts.action;

import com.myapp.hibernate.model.Combate;
import com.myapp.hibernate.util.CombateUtil;
import com.myapp.struts.form.CombatesForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


public class ActualizarCombateAction extends org.apache.struts.action.Action {

    private static final String SUCCESS = "success";

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        CombatesForm formulario = (CombatesForm) form;
        CombateUtil combateUtil = new CombateUtil();
        
        if(formulario.getRadio()!=null){
            Combate c = combateUtil.obtenerCombate(formulario.getIdCombate());
            c.setIdGanador(Integer.parseInt(formulario.getRadio()));
            combateUtil.actualizaCombate(c);
            request.getSession().setAttribute("informacion", "Combate modificado correctamente");
        }
        
        return mapping.findForward(SUCCESS);
    }
}